perm filename A47[106,RWF] blob sn#790301 filedate 1985-03-15 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	_Printing Geometrical Images_
C00007 ENDMK
CāŠ—;
_Printing Geometrical Images_

To print characters along a line in the output page within a nested
iteration of the form

FOR R:= 1 TO RMAX DO
     BEGIN
     FOR C:= 1 TO CMAX DO
	(* write correct character for (R,C)*);
WRITELN
END.

find the equation f(R,C)=0 for the line, and use the condition

IF f(R,C) = 0
THEN WRITE('*')
ELSE WRITE(' ')

				IF R+C=6 (* F = R+C - 6 *)
				THEN WRITE('*')
				ELSE WRITE(' ')


To print characters on one side of a line, use the appropriate case of

IF f(R,C) > 0
IF f(R,C) < 0
IF f(R,C) >= 0
IF f(R,C) <= 0

where the latter two are appropriate if the dividing line is itself to be dark.

				IF R+C <= 6 THEN ...


				IF SQR(R-7)+SQR(C-8)<=18 THEN ...


Shaded regions defined by several lines can be put together using AND and OR
on the conditions for the separate lines:

				IF (R+C>=0) OR (SQR(R)+SQR(C)<=25) THEN ...


				IF (R+C>=0) AND (SQR(R)+SQR(C)<=25) THEN ...


In the first image, where the line and circle cross, three of the adjacent
regions are shaded, so OR is correct. In the second, only one is shaded, so
AND is correct.

A common situation has two of the four regions, diagonally opposite, shaded
at a crossing. If the equations of the lines are f(R,C)=0 and g(R,C)=0,
test the product f(R,C)*g(R,C):


	R-C=0	           R+C-8=0		(R-C)*(R+C-8)>0


If you want the dividing lines to be dark, use >= or <= :


program PinWheel(output)
	const Size = 10;
	var Col, Row : integer;
begin (* PinWheel *)
	for Row:= - Size to Size do begin
		for Col:= -Size to Size do
			if (Col * Row * (Col-Row)*(Col+Row))) >= 0 then write ('*')
			else write(' ');
		writeln;
	end;
end. (* PinWheel *)


In the above image, the oval line f=0 separates the image into an outer part
where the test g<0 must be made, and an inner part where h<0 must be tested.
We therefore make the test on f first.

IF f<0 THEN
	IF h<0 THEN WRITE(' ') ELSE WRITE('*')
ELSE
	IF g<0 THEN WRITE(' ') ELSE WRITE('*')

Rule of good programming practice: Wherever you can, split a problem into
pieces such that some of the difficult aspects of the problem are restricted
to each piece. In short: DIVIDA UT IMPERE (DIVIDE AND CONQUER).

After having designed a program that prints an image, we decide to overlay
it with a one-inch grid of asterisks. Using the condition

IF (R MOD 6=0) OR (C MOD 10=0)
THEN WRITE('*')
ELSE whatever we had before

gives priority to the grid, and thereby lays it over the other image.


To print alternate dark and white stripes, each five characters wide, notice
that the sum R+C indicates which diagonal we are on, and diagonals separated
by multiples of ten are the same shade, so we may test (R+C) MOD 10.

The correct condition is

IF (R+C) MOD 10<5
THEN WRITE(' ')
ELSE WRITE('*')



				The repeated pattern


IF (R MOD 6=0) OR (C MOD 10=0)
THEN WRITE('*')
ELSE
	IF (R MOD 12-6) * (C MOD 20-10)>0
	(*1*)
	THEN WRITE('/')
	ELSE WRITE(' ')

Drill: what happens if we insert
	AND (R+C)MOD 3=0,
at (*1*)?